<?php
/**
 * Database class, for connecting, querying etc.
 *
 *
 */
defined('SECUR_CHECK') or die("Security error");
/**
 * Database class, all db action will be perfomed in this class.
 *
 */

class database {
    function  __construct() {
        global $conf;
        $this->handler = mysql_connect($conf->db_host, $conf->db_user, $conf->db_pass) or die ("Error connecting to database");
        mysql_select_db($conf->db_db);
    }

    function sql_array($sql) {
        //$sql = mysql_real_escape_string($sql);
        $result = mysql_query($sql, $this->handler) or die("error while executing query '$sql'");
        $return = false;
        if($result && mysql_num_rows($result) > 0)
        {
            $return = array();
            while($row = mysql_fetch_assoc($result))
            {
                $return[] = $row;

            }
        }
        return $return;
    }
    /*
     * Escapes and trims data for insertion
     */
    function escape($value)
    {
        if(is_array($value))
        {
            foreach ($value as $key => $row)
            {
                $return[$key] = mysql_real_escape_string(trim($row));
            }
        }
        else
        {
            $return = mysql_real_escape_string(trim($value));
        }
        return $return;
    }
    function sql_exe($sql) {
        mysql_query($sql, $this->handler) or die("error while executing query '$sql'");
        return true;
    }

    function  __destruct() {
        @mysql_close($this->handler);
    }
}
?>